package com.wo.cloud.security;

import com.wo.cloud.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2021/4/18 22:22
 * Description: 密码加密类
 */

@Component
public class DefaultPasswordEncoder implements PasswordEncoder {

    @Autowired
    private PasswordEncoder encoder;

    /**
     * 密码进行md5加密
     *
     * @param rawPassword
     * @return
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }

    /**
     * 用户密码对比
     *
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equalsIgnoreCase(MD5.encrypt(rawPassword.toString()));
    }
}
